package com.dkm.ec.cart.repository.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.cart.domain.CartEntity;
import com.dkm.ec.cart.persistence.dao.CartEntityQueryDao;
import com.dkm.ec.cart.persistence.entity.CartEntityPo;
import com.dkm.ec.cart.repository.CartEntityRepository;

/**
 * 对象功能:购物车 Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-05-17 23:30:36
 */
@Repository
public class CartEntityRepositoryImpl extends AbstractRepository<String, CartEntityPo,CartEntity> implements CartEntityRepository{
	  
	@Resource
	private  CartEntityQueryDao cartEntityQueryDao;

	public CartEntity newInstance() {
		CartEntityPo po = new CartEntityPo();
		CartEntity cartEntity = SpringHelper.getBean(CartEntity.class);
		cartEntity.setData(po);
		return cartEntity;
	}

	public CartEntity newInstance(CartEntityPo po) {
		CartEntity cartEntity = SpringHelper.getBean(CartEntity.class);
		cartEntity.setData(po);
		return cartEntity;
	} 
	
	@Override
	protected IQueryDao<String, CartEntityPo> getQueryDao() {
		return cartEntityQueryDao;
	}

	@Override
	public Integer getUserCartQty(Long userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		return cartEntityQueryDao.countByKey("getUserCartQty", params);
	}
	
}
